import { isObject,hasOwnProperty,isEqual } from "../shared/utils";
import { reactive } from "./reactive.js";

const get = createGetter(),
      set = createSetter();
    
function createGetter(){
    return function get(target,key,receiver){
        const res = Reflect.get(target,key,receiver);
        // return target[key];
        // console.log('Reflect获取',target[key])
        if(isObject(res)){
            return reactive(res);
        }
            return res;
    }
}

function createSetter(){
    return function set(target,key,value,receiver){
            const isKeyExist = hasOwnProperty(target, key),
            oldValue = target[key],
            
            res = Reflect.set(target,key,value,receiver);
            if(!isKeyExist){
                // console.log('新增',value)
            }else if(!isEqual(value,oldValue)){
                // console.log('修改',value)
            }
            return res
    }
}

const mutableHandler = {
    // get(){

    // },

    // set(){

    // }
    get,
    set
}
export {
    mutableHandler
}